/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.view.panels;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import org.jfonia.connect5.basics.MutableValueNode;

/**
 *
 * @author Rik Bauwens
 */
public class EditorPanel extends BasicNodePanel implements MouseMotionListener
{
        private Image image;
        private int xMousePos;
        private int yMousePos;

        public EditorPanel(MutableValueNode<Double> xNode, MutableValueNode<Double> yNode,
                           MutableValueNode<Double> width, MutableValueNode<Double> height)
        {
                super(xNode, yNode, width, height);
                setOpaque(false);
        }

        public  void dragStart(Image image)
        {
                this.image = image;
                addMouseMotionListener(this);
                setVisible(true);
        }

        public void dragStop()
        {
                image = null;
                removeMouseMotionListener(this);
                setVisible(false);
        }

        @Override
        public void paintComponent(Graphics g)
        {
                super.paintComponent(g);
                if(image != null)
                        g.drawImage(image, xMousePos, yMousePos, this);
        }

        public void mouseMoved(MouseEvent e) {
                xMousePos = e.getX();
                yMousePos = e.getY();
                repaint();
        }
        
        public void mouseDragged(MouseEvent e) {}
}
